<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h3>基础表达式为：aX^2 + bX + c = 0</h3>
<h4>a的值：</h4>   <input type="text" id="a">
<h4>b的值：</h4>   <input type="text" id="b">
<h4>c的值：</h4>   <input type="text" id="c">
<input type="button" name="Submit" value="计 算" onclick="end();" />
<br>
<br>
<br>
x1的值为   <p id="text1">等待计算</p>
<br>
X2的值为    <p id="text2">等待计算</p>
<script>
    function end(){
        var patt = /[0-9]+/
        var gia = document.getElementById("a").value
        var gib = document.getElementById("b").value
        var gic = document.getElementById("c").value
        var x1
        var x2
        if(patt.test(gia)||patt.test(gib)||patt.test(gic)){
            alert("必须输入数字")
        }
        if(gia == "0"){               
            alert("error:a不能是0不能计算")
        }
        if((Math.pow(gib,2)-4*gia*gic)<0){
            alert("error:b^2-4ac不得小于0")
        }
        //计算开始
        x1 = ((-gib)+Math.pow((Math.pow(gib,2)-4*gia*gic),0.5))/2*gia
        document.getElementById("text1").innerHTML = x1
        x2 = ((-gib)-Math.pow((Math.pow(gib,2)-4*gia*gic),0.5))/2*gia
        document.getElementById("text2").innerHTML = x2
    }
</script>
</body>
</html>